﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataBaseAccess
{
    public class DataBaseTester
    {
        DataBaseCreation dbCreate;
        DataBaseConnection dbConnect;
        int max = 100000;

        public DataBaseTester()
        {
            dbConnect = new DataBaseConnection();
            dbCreate = new DataBaseCreation(dbConnect);
        }

        public void testAll()
        {
            dbCreate.CreateNewDatabase();
            insertTestData();
        }

        private void insertTestData()
        {
            insertTestPerson();
            insertTestMovie();
            insertTestActor();
        }

        private void insertTestPerson()
        {
            Console.WriteLine("Starting on Person");
            List<string> statements = new List<string>();
            
            for (int i = 0; i < max; i++)
            {
                string sql = "INSERT INTO Person (first_name, last_name) VALUES ('Keanu', 'Reeves');";
                statements.Add(sql);
            }
            dbConnect.ExecuteCommandNoReturn(statements);
        }

        private void insertTestMovie()
        {
            Console.WriteLine("Starting on Movie");
            List<string> statements = new List<string>();

            for (int i = 0; i < max; i++)
            {
                string sql = "INSERT INTO Movie (title, owned_by) VALUES ('Matrix, the', 1);";
                statements.Add(sql);
            }
            dbConnect.ExecuteCommandNoReturn(statements);
        }

        private void insertTestActor()
        {
            Console.WriteLine("Starting on Actor");
            List<string> statements = new List<string>();

            for (int i = 0; i < max; i++)
            {
                string sql = String.Format("INSERT INTO Actor VALUES ({0},{1});", i + 1, i + 1);
                statements.Add(sql);
            }
            dbConnect.ExecuteCommandNoReturn(statements);
        }
    }
}
